package cn.yunhe.action;

import cn.yunhe.entity.House;
import cn.yunhe.entity.Type;
import cn.yunhe.services.SearchHouseService;
import cn.yunhe.util.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import net.sf.json.JSONArray;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class SearchHouseAction extends BaseAction implements ModelDriven {
    private House house;
    private Type type;
    private PrintWriter out;

    public String searchHouse() throws IOException {
        SearchHouseService searchHouseService = new SearchHouseService();
        List<House> houseList = searchHouseService.searchHouse(house);
        JSONArray jsonArray = new JSONArray();
        jsonArray.addAll(houseList);
        out = getResponse().getWriter();
        out.print(jsonArray);
        return null;
    }

    @Override
    public Object getModel() {
        if (house == null) {
            house = new House();
        }
        if (type==null){
            type=new Type();
        }
        house.setType(type);
        return house;
    }

}
